<div class="container">
    <div class="row">
        <?php if (count($inboxAll) > 0) { ?> 
            <div id="AjaxLoader_id" style="display:none;" align="center">&nbsp;<img src="<?php echo ThemePath(); ?>/img/fancybox_loading@2x.gif" align="absmiddle"></div>
            <div class="span3">
                <div class="tabBox">
                    <ul class="innerTab">
                        <?php
                        $i = 0;
                        foreach ($inboxAll as $inbox) {
                            $userDetails = Profiles::model()->findByAttributes(array('user_id' => $inbox->from_users_id));
                            $imagePath = $inbox->from_users_id;
                            if ($userDetails->photo <> "") {
                                $imgsrc = baseUrl() . '../../' . getUploadDir() . $imagePath . '/profile/minithumb/' . $userDetails->photo;
                            } else {
                                $imgsrc = baseUrl() . '../../upload/default-mini.png';
                            }
                            ?>
                            <li <?php if ($i == 0) { ?>class="active"<?php } ?> ><a href="javascript:void(0);" onclick="return MessageByuserId(<?php echo $inbox->from_users_id; ?>,<?php echo $inbox->backend_user_id; ?>,<?php echo $inbox->classes_id; ?>);">
                                    <img src="<?php echo $imgsrc; ?>" title="<?php echo $userDetails->first_name; ?>" alt="<?php echo $userDetails->first_name; ?>" />
                                    <?php echo $userDetails->first_name; ?></a>

                            </li>
                            <!--<div style="margin-left:100px; margin-top:-50px;"><img src="<?php echo ThemePath(); ?>/images/unread.png" height="8" width="8" /></div>-->
                            <?php
                            $i++;
                        }
                        ?>
                    </ul>
                    <div class="clear"></div>                   
                </div>
            </div>


            <script language="javascript">
                $(document).ready(function() {
                    MessageByuserId(<?php echo $inboxAll[0]->from_users_id; ?>,<?php echo $inboxAll[0]->to_user_id; ?>,<?php echo $inboxAll[0]->classes_id; ?>);
                });
            </script>

            <div class="span9">
                <div class="msgBox">
                    <div class="padding20px" id="detailInbox">
                    </div>
                </div>

            </div>
        <?php } else { ?>
            No any mail.
<?php } ?>
    </div>
</div>


<script language="javascript">
    $(document).ready(function() {
        $(function() {
            $('.innerTab li a').click(function(e) {
                e.preventDefault();
                var $this = $(this);
                $this.closest('ul').children('li').removeClass('active');
                $this.parent().addClass('active');
            });
        });
    });

    function MessageByuserId(fromuid,touid,classid) {
        jQuery.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/GetMessage"); ?>",
            data: 'classid=' + classid+'&fromuid=' + fromuid+'&touid=' + touid ,
            'success': function(data) {
                $('#detailInbox').html(data);
	   
            },
            'cache': false});

    }
    function showMsgBlock(checkval) {
        if(checkval==1){$("#replybtn").hide();}else{$("#replybtn").show();}
        $("#send_a_msg_box").toggle('slow').show();
    }


    function replyAMailToUser(classcoursetype,classid, userid, getMessagesUID) {
        var subject = $("#subject_id").val();
        var msgval = $("#message_text_id").val();

        if (msgval == '') {
            $("#errorMessage_msg_id").text('Message  can not blank.')
            return false;
        }
        if(subject != '' && msgval != '') {
            jQuery.ajax({
                'type': 'POST',
                'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/sendMailTouser"); ?>",
                'data': "selectedUser=" + userid + "&subject=" + subject + "&msgval=" + msgval + "&classId=" + classid+ "&type=" + classcoursetype,
                'beforeSend': function(jqXHR, settings) {
                    $("#AjaxLoader_id").show();
                },
                'success': function(data) {
                    if($.trim(data)=='success') {
                        $("#AjaxLoader_id").hide();
                        MessageByuserId(userid,getMessagesUID,classid);
                    }
                },
                'cache': false
            });
        }

    }


</script>
<style>
    .span9{
        width: 100%;
    }
</style>
